package com.lb.uts.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lb.uts.entity.ActiveClient;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 记录当前存活的client Mapper 接口
 * </p>
 *
 * @author cacframe
 * @since 2019-04-26
 */
@Repository
@Mapper
public interface ActiveClientMapper extends BaseMapper<ActiveClient> {
    /**
     * 统计现在的存活的执行器信息,以systemName进行分组
     *
     * @return 执行器信息，格式：system:ip1,ip2
     * @Author liangb
     * @Date 2019/4/28 10:44
     */
    @Select("select system_name systemName,GROUP_CONCAT(ip) as ips from active_client GROUP BY system_name")
    List<Map<String, String>> groupBySystemName();


    /**
     * 物理删除，已经失效的执行器
     *
     * @param systemName 系统名
     * @param ip 
     * @return 删除条数
     */
    @Delete("delete from active_client where system_name = #{systemName} and ip  =#{ip}")
    int deleteBySystemNameAndIp(@Param("systemName") String systemName, @Param("ip") String ip);

}
